<%@include file="connection.jsp"%>

<%

	String userid = (String) session.getAttribute("userid");

    if (userid == null)
    {
       response.sendRedirect("login.jsp");
    }
    
    
          Connection c = getConnection(session);
          Statement s = c.createStatement();

            String doc_code= request.getParameter("doc_code");
            String icd_code[] = request.getParameterValues("icd_code"); 
            String cpt_code[] = request.getParameterValues("cpt_code");          
			
			String returnPath="template_diag.jsp";
			
            if (icd_code != null) {
            	s.executeUpdate("delete from tblsuperbilltemplate_diag where DocCode = '" +doc_code+ "'");
                for (int i = 0; i < icd_code.length; i++) {
                    s.executeUpdate("insert into tblsuperbilltemplate_diag (DocCode, DiagCode) values('" +doc_code+ "', '" + icd_code[i] + "')");
                }
            }
             if (cpt_code != null) {
             	s.executeUpdate("delete from tblsuperbilltemplate_proc where DocCode = '" +doc_code+ "'");
                for (int i = 0; i < cpt_code.length; i++) {
                    s.executeUpdate("insert into tblsuperbilltemplate_proc (DocCode, ProcCode) values('" + doc_code + "', '" + cpt_code[i] + "')");
                }
                returnPath="template_proc.jsp";
            }

            out.print("Data Saved.");
            
            s.close();
            c.close();
            
            response.sendRedirect(returnPath+"?saved=1");
            
%>
<a href="home.jsp"/>Back</a>
